//
//  ViewController.m
//  柱状图Demo
//
//  Created by mac on 16/6/5.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ViewController.h"
#import "ChartView.h"
#import "NetWorkManager.h"
#import "DateTransform.h"
#define GetStockTradeData @"http://robin.iok.la/LHWeb/Api/GetStockTradeData?code=000001.SZ"

@interface ViewController ()

@property (nonatomic, strong) ChartView *chartView;

@property (nonatomic ,strong)NSArray *dataArray;

@property (nonatomic ,strong)NSArray *dateArray;
@end

@implementation ViewController


-(void)dataGetStockQuantifyData2{
    //NSString *str1 =[GetStockQuantifyData stringByAppendingString:_codeStr];
    [NetWorkManager getUrl:@"http://robin.iok.la/LHWeb/Api/GetStockTradeData?code=000001.SZ" paramdic:nil success:^(id data) {
        NSMutableArray *amountArray = [NSMutableArray array];
        NSMutableArray *dateArray = [NSMutableArray array];
        NSMutableArray *array = [data[@"FundList"] mutableCopy];
        for (NSDictionary *dic in array) {
            
            NSString *amountStr =dic[@"Amount"];
            
            NSString *dateStr = [NSString stringWithFormat:@"%@",dic[@"Date"]];
            
            NSString *str  = [dateStr substringWithRange:NSMakeRange(6, 10)];
            NSString *str2 = [DateTransform dateTransformTodate:str];
            NSLog(@"%@",str);
            NSLog(@"日期格式%@",str2);
            
            
            [amountArray addObject:amountStr];
            [dateArray addObject:str2];
            
        }
        self.dataArray = amountArray;
        self.dateArray = dateArray;
        
        
        _chartView.yields = self.dataArray;
        _chartView.dayPoints = self.dateArray;
        
        
    } error:^(id error) {
        NSLog(@"%@",error);
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.chartView = [[ChartView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, 200)];
    _chartView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_chartView];
    
    [self dataGetStockQuantifyData2];
    
    // Do any additional setup after loading the view, typically from a nib.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
